package com.roger.myHome.controller;

import com.roger.myHome.entity.Menu;
import com.roger.myHome.entity.MenuReq;
import com.roger.myHome.service.MenuService;
import com.roger.myHome.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    @GetMapping (value = "/loadMenu",produces="text/html;charset=UTF-8")
    public String loadMenu(){
        MenuReq menuReq = new MenuReq();
        menuReq.setParentId(0L);
        List<Menu> menusList = menuService.selectMenus(menuReq);
        String json = StringUtils.listToJson(menusList);
        return json;
    }

    @GetMapping(value = "/loadChildrenMenu",produces="text/html;charset=UTF-8")
    public String loadChildMenu(Long parentId){
        MenuReq menuReq = new MenuReq();
        menuReq.setParentId(parentId);
        List<Menu> menusList = menuService.selectMenus(menuReq);
        return StringUtils.listToJson(menusList);
    }


}
